<template>
  <div class="search">
    <ke-header></ke-header>
    <div class="content">
      <ul class="courseList">
        <li v-for="(course, index) in courseList" :key="index" @click="handleToOpencourse(index)">
          <ke-intro
            :price="course.courseSrc.price"
            :courseName="course.courseSrc.coursename"
            :buyNumber="course.courseSrc.buyNum"
            :teacherName="course.courseSrc.teacherName"
          />
        </li>
      </ul>
    </div>
    <div class="footer">
      <ke-footer />
    </div>
  </div>
</template>

<script>
export default {
  name: 'search',
  components: {
    keHeader: () => import('../components/ke-header'),
    keFooter: () => import('../components/ke-footer'),
    keIntro: () => import('../components/ke-intro')
  },
  data() {
    return {
      courseList: null
    }
  },
  mounted() {
    this.courseList = this.$store.state.searchCourse
    console.log(this.courseList)
  },
  methods: {
    handleToOpencourse(index) {
      this.courseSrc = this.courseList[index]
      console.log(this.courseSrc)
      this.$store.dispatch('setCourseSrc', this.courseSrc)
      this.$router.push('/opencourse/overview')
    }
  }
}
</script>

<style lang="stylus" scoped>
.search {
  position: absolute;
  top: 0px;
  left: 0px;
  right: 0px;
  bottom: 0px;

  .content {
    width: 1200px;
    margin: 10px auto 10px;
    height: 500px;

    .courseList {
      height: 498px;
      padding-left: 0;
      overflow: scroll;
      border-top: 8px solid #eeeeee;
      padding-top: 8px;
      box-sizing: border-box;

      &::-webkit-scrollbar {
        width: 0px;
      }

      li {
        list-style: none;
        float: left;
        width: 240px;
        height: 234px;
        box-sizing: border-box;
        cursor: pointer;
        border: 1px solid transparent;

        &:hover {
          border: 1px solid #dddddd;
        }
      }
    }
  }

  .footer {
    position: absolute;
    width: 100%;
    bottom: 0px;
  }
}
</style>
